<template>
  <el-form :model="ruleForm" status-icon  ref="ruleForm" label-width="100px" class="demo-ruleForm">
    <el-form-item label="名称" prop="throneName">
    <el-input type="text" readonly="readonly" v-model="ruleForm.throneName" autocomplete="off"></el-input>
  </el-form-item>
  <el-form-item label="描述" prop="throneDesc">
    <el-input type="text" v-model="ruleForm.throneDesc" autocomplete="off"></el-input>
  </el-form-item>

  <el-form-item label="域名" prop="thronePath">
    <el-input readonly="readonly" v-model.number="ruleForm.thronePath"></el-input>
  </el-form-item>
  <el-form-item>
    <el-button type="primary" @click="submitForm('ruleForm')">修改</el-button>
    <el-button @click="resetForm('ruleForm')">返回</el-button>
  </el-form-item>
</el-form>
</template>

<script>
import {updateThrone} from '../services/ThroneService.js'
export default {
    created(){
        var resp = this.$route.params;
        this.ruleForm.throneId = resp.throneId;
        this.ruleForm.throneName = resp.throneName;
        this.ruleForm.throneDesc = resp.throneDesc;
        this.ruleForm.thronePath = resp.thronePath;
    },
data() {
      return {
        ruleForm: {
            throneId:'',
            throneName: '',
            throneDesc: '',
            thronePath: '',
        },
      };
    },
    methods: {
       submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            updateThrone(this.ruleForm).then((resp) => {
              if(resp.data == "true"){
                this.$router.push({name:"Throne"});
              }else{
                alert("服务器正忙，修改失败");
              }
            });
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
      resetForm(formName) {
        this.$router.push({name:"Throne"});
      },
    }
  }
</script>

<style>

</style>